package DB;

import java.util.Iterator;
import java.util.Vector;
import objects.*;
import objects.User.Type;

public class MainTest
{

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException
	{
		DataBase db = new DataBase();
//		db.addForum("f1");
//		db.addThreadToFroum("f1", "thread1");
		User tal = new User();
		tal.setUserName("tal");
		tal.setActive(true);
		tal.setType(User.Type.DefaultUser);
		db.addUser(tal);
		db.removeUser(tal);
		
		Vector<User> uv = db.getUsers();
		System.out.println("*****************************");
		for (Iterator<User> iterator = uv.iterator(); iterator.hasNext();)
		{
			User user = (User) iterator.next();
			System.out.println("User: "+user.getUserName());
		}
//		User user = db.findUser("tal");
//		Frm forum = db.findFroum("f1");
//		Trd thread = db.getThread(forum, "thread1");
////		db.addMessage(thread, "title1", user, "msgStr1");
//		
//		Vector<Message> vecMsg = db.getMessageFromThread("f1", "thread1");
//		System.out.println("TAL: " +vecMsg.get(0).getMessage());
//		int i = db.editMessageInThread(forum, user, "thread1", "title1", "new message1");
//		System.out.println("answer: "+i);
		
//		User owner = db.findOwnerOfMessage("f1", "thread1", "title1");
//		//Message m = db.getMessage(thread,"title1");
//		
//		int i = db.removeMessageFromThread(forum, "thread1", "title1");
//		System.out.println(i);
		
		/*db.addUser("tal",Type.MANAGER);
		User u = db.findUser("tal");
		System.out.println("RESUALT1: "+u.getUserName()+", "+u.getType().toString());
		
		db.addForum("f1");
		db.addForum("f2");
		Frm frm1 = db.findFroum("f1");
		Frm frm2 = db.findFroum("f2");
		System.out.println("RESUALT2: "+frm1.getForumName());
		
		db.addThreadToFroum(frm1.getForumName(), "threadName1");
		db.addThreadToFroum(frm2.getForumName(), "threadName2");
		Trd t = db.getThread(frm1, "threadName1");
		System.out.println("RESUALT3: "+t.getThreadName()+", "+t.getForum().getForumName());

		db.addMessage(t, "title2", u, "msgStr");
		Message m = db.getMessage(t, "title2");
		System.out.println("RESUALT4: "+m.getTitle()+", "+m.getMessage());*/
		
		
		//m.setMessage("rrrrrrrrrrrrrrrr");
		//db.updateObject(m);
		//db.deleteObject(m);
		//t.setThreadName("222");
		//db.updateObject(t);
		
		//db.deleteObject(frm1); //when deleting, it should delete all the thread's messages,
							//it tries to delete something and does not successeds  
		//db.deleteObject(u); //when deleting a user it tries to delete this user's messages??? why??
			
		/*db.addUser("Inbal",Type.DefaultUser);
		db.addUser("Ori",Type.DefaultUser);
		User u1 = db.findUser("Inbal");
		User u2 = db.findUser("Ori");

		
		db.addFriend(u, u1);
		db.addFriend(u, u2);
		
		Vector<User> ut = db.getFriendsOfUser("tal");
		System.out.println("Size of freinds list" + ut.size() + "User: " + ut.elementAt(0).getUserName());
		System.out.println("Size of freinds list" + ut.size() + "User: " + ut.elementAt(1).getUserName());
		
		
		System.out.println(db.getForums().elementAt(0).getForumName());
		System.out.println(db.findOwnerOfMessage("f1", "threadName1", "msgStr").getUserName());
		System.out.println(db.getThreads(frm1).elementAt(0).getThreadName());
		System.out.println(db.getMessageFromThread("f1", "threadName1").elementAt(0).getMessage());
		
		db.removeUser(u);
		if(u.getStatus().equals(Status.NOT_ACTIVE))
			System.out.println("good!");
		if(u1.getStatus().equals(Status.ACTIVE))
			System.out.println("good!");
		
		System.out.println(db.getUsers());*/
		
		
	}

}
